import BaseUtil from '@/BaseUtil';
import MathUtil from '@/MathUtil';
import RandomUtil from '@/RandomUtil';
import SelectUtil from '@/SelectUtil';
import AbilityBase from 'code/Scripts/Abilities/base/AbilityBase';
/**
 * 海潮之怒
 **/
export default class BossSpell_SeaFury extends AbilityBase {
    static instance: BossSpell_SeaFury;
    constructor(id: string = 'Mst2') {
        super(id);
        BossSpell_SeaFury.instance = this;
        this.init();
        se.onUnitSpellEffect(this.onSpellEffect.bind(this), this.id);
    }
    init() {}
    cast<T extends Object = any>(tarX: number, tarY: number, source: unit, target: unit, data?: T): void {
        BossAbilityManagerInstance.text('海潮之怒', source);
        BaseUtil.onTimer(0.1, (c) => {
            let { x: tx, y: ty } = MathUtil.polarProjection(GetUnitX(source), GetUnitY(source), RandomUtil.nextInt(100, 800), RandomUtil.randomAngle());
            let mark = AddSpecialEffect(BossAbilityManagerInstance.SpellMark, tx, ty);
            BaseUtil.runLater(1, () => {
                this.damage(source, mark, tx, ty);
            });
            return c < 40;
        });
        BaseUtil.runLater(10, () => {
            source = null;
        });
    }
    damage(u: unit, ef: effect, tx: number, ty: number) {
        DestroyEffect(AddSpecialEffect('Objects\\Spawnmodels\\Naga\\NagaDeath\\NagaDeath.mdl', tx, ty));
        let es = SelectUtil.getEnemyUnitsInRange(u, 225, tx, ty);
        DamageSystemInstance.applyAoeMagicDamage(es, u, 1000, 'ice');
        DestroyEffect(ef);
    }
    onSpellEffect() {
        this.cast(GetSpellTargetX(), GetSpellTargetY(), GetTriggerUnit(), GetSpellTargetUnit());
    }
}
